package cn.drh.charging.order.mqtt;


import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @ClassName MqttProducer
 * @Description TODO
 * @Author renhong~Deng
 * @Date 2025/5/28 11:40
 * @Version 1.0
 * emqx消息发送工具
 */

@Slf4j
@Component
public class MqttProducer {
    @Autowired
    private MqttClient mqttClient;

    /**
     * 通过mqttClient给emqx发送消息
     * @param topic 主题
     * @param message 消息
     */
    public void send(String topic, String message) {
        try {
            mqttClient.publish(topic, message.getBytes(), 0, true);
        } catch (Exception e) {
            log.error("MqttProducer send error", e);
        }
    }
}
